package moe.eairpeter.sfpapi;

import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

/**
 * @author EAirPeter
 *
 */
public class SlimefunPlaceholder extends JavaPlugin {
    
    private final BukkitRunnable task = new TaskReadAll(this);
    private final PlaceholderHook hook = new PlaceholderHook(this);
    
    @Override
    public void onEnable() {
        PluginManager pm = Bukkit.getPluginManager();
        Validate.isTrue(
            pm.isPluginEnabled("Slimefun"),
            "The plugin Slimefun is required."
        );
        Validate.isTrue(
                pm.isPluginEnabled("PlaceholderAPI"),
            "The plugin PlaceholderAPI is required."
        );
        task.runTaskTimer(this, 0L, 20L);
        Validate.isTrue(
            hook.hook(),
            "Failed to hook into PlaceholderAPI"
        );
    }
    
    @Override
    public void onDisable() {
        task.cancel();
    }
    
}
